/*----------------------------------------------------------------------------*/
/* Copyright (c) 2013 Worthington Robot Club. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package us.oh.k12.wkw.robot.util;

import edu.wpi.first.wpilibj.NamedSendable;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 * wrapper class for SmartDashboard.
 */
public class WkwDashboard {

    private static final String STATUS_NAME_ROBOT_INITALIZED_AT = "Robot Initialized At";
    private static final String STATUS_NAME_ROBOT_PROGRAM_VERSION = "Robot Program Version";
    private static final String STATUS_NAME_ROBOT_STATE_DISABLED = "Robot Disabled State";
    private static final String STATUS_NAME_ROBOT_STATE_AUTONOMOUS = "Robot Autonomous State";
    private static final String STATUS_NAME_ROBOT_STATE_TELEOP = "Robot Teleop State";
    private static final String STATUS_NAME_ROBOT_STATE_TEST = "Robot Test State";
    private static final String STATUS_NAME_DRIVE_LEFT_MOTOR_SPEED = "Drive Left Motor Speed";
    private static final String STATUS_NAME_DRIVE_RIGHT_MOTOR_SPEED = "Drive Right Motor Speed";
    private static final String STATUS_NAME_DRIVE_LEFT_JOYSTICK_X = "Drive Left Joystick X";
    private static final String STATUS_NAME_DRIVE_LEFT_JOYSTICK_Y = "Drive Left Joystick Y";
    private static final String STATUS_NAME_DRIVE_RIGHT_JOYSTICK_X = "Drive Right Joystick X";
    private static final String STATUS_NAME_DRIVE_RIGHT_JOYSTICK_Y = "Drive Right Joystick Y";
    private static final String STATUS_NAME_SHOOTER_MOTOR_TOTAL_ON_TIME = "Shooter Motor Total On Time";
    private static final String STATUS_NAME_SHOOTER_SPEED = "Shooter Speed";
    private static final String STATUS_NAME_ANGLE_SPEED = "Angle Speed";
    private static final String STATUS_NAME_SHOOTER_DESIRED_SPEED = "Shooter Desired Speed";
    private static final String STATUS_NAME_ANGLE_DESIRED_SPEED = "Angle Desired Speed";
    private static final String STATUS_NAME_BATTERY_VOLTS = "Battery Volts";
    private static final String STATUS_NAME_TOP_SWITCH = "Top Switch";
    private static final String STATUS_NAME_BOTTOM_SWITCH = "Bottom Switch";
    private static final String STATUS_NAME_PLUNGER = "Plunger";
    private static final String STATUS_NAME_PLUNGER_FIRE_COUNT = "Plunger Fire Count";
    private static Object lock = new Object();
    private static WkwDashboard instance = null;

    /**
     * hidden null constructor.
     */
    private WkwDashboard() {
        super();
    }

    private static WkwDashboard getInstance() {

        synchronized (WkwDashboard.lock) {

            if (null == WkwDashboard.instance) {
                WkwDashboard.instance = new WkwDashboard();
            }
        }

        return WkwDashboard.instance;
    }

    private void setStatus(final String pName, final String pValue) {
        NetworkTable.getTable("SmartDashboard").putString(pName, pValue);
    }

    private void setStatus(final String pName, final double pValue) {
        NetworkTable.getTable("SmartDashboard").putNumber(pName, pValue);
    }

    private void setStatus(final String pName, final int pValue) {
        NetworkTable.getTable("SmartDashboard").putNumber(pName, pValue);
    }

    private void setStatus(final String pName, final boolean pValue) {
        NetworkTable.getTable("SmartDashboard").putBoolean(pName, pValue);
    }

    public static void putData(final String pName, final NamedSendable pValue) {
        NetworkTable.getTable("SmartDashboard").putValue(pName, pValue);
    }

    /*
     * 
     * 
     * convenience methods.
     * 
     */
    public static void setRobotInitialized(final String pDateTime) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ROBOT_INITALIZED_AT,
                pDateTime);
    }

    public static void setRobotVersion(final String pVersion) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ROBOT_PROGRAM_VERSION,
                pVersion);
    }

    public static void setDisabledStateChange(final boolean pState) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ROBOT_STATE_DISABLED, pState);
    }

    public static void setAutonomousStateChange(final boolean pState) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ROBOT_STATE_AUTONOMOUS,
                pState);
    }

    public static void setTeleopStateChange(final boolean pState) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ROBOT_STATE_TELEOP, pState);
    }

    public static void setTestStateChange(final boolean pState) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ROBOT_STATE_TEST, pState);
    }

    public static void setDriveLeftMotorSpeed(final double pSpeed) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_DRIVE_LEFT_MOTOR_SPEED,
                pSpeed);
    }

    public static void setDriveRightMotorSpeed(final double pSpeed) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_DRIVE_RIGHT_MOTOR_SPEED,
                pSpeed);
    }

    public static void setDriveLeftJoystickX(final double pX) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_DRIVE_LEFT_JOYSTICK_X, pX);
    }

    public static void setDriveLeftJoystickY(final double pY) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_DRIVE_LEFT_JOYSTICK_Y, pY);
    }

    public static void setDriveRightJoystickX(final double pX) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_DRIVE_RIGHT_JOYSTICK_X, pX);
    }

    public static void setDriveRightJoystickY(final double pY) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_DRIVE_RIGHT_JOYSTICK_Y, pY);
    }

    public static void setShooterMotorTotalOnTime(final long pTime) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_SHOOTER_MOTOR_TOTAL_ON_TIME,
                (int) pTime);
    }

    public static void setShooterSpeed(final double pSpeed) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_SHOOTER_SPEED, pSpeed);
    }

    public static void setAngleSpeed(final double pSpeed) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ANGLE_SPEED, pSpeed);
    }

    public static void setShooterDesiredSpeed(final double pSpeed) {
        WkwDashboard.getInstance()
                .setStatus(WkwDashboard.STATUS_NAME_SHOOTER_DESIRED_SPEED, pSpeed);
    }

    public static void setAngleDesiredSpeed(final double pSpeed) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_ANGLE_DESIRED_SPEED, pSpeed);
    }

    public static void setBatteryVolts(final double pVolts) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_BATTERY_VOLTS, pVolts);
    }

    public static void setTopSwitchState(final boolean state) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_TOP_SWITCH, state);
    }

    public static void setBottomSwitchState(final boolean state) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_BOTTOM_SWITCH, state);
    }

    public static void setPlungerState(final boolean state) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_PLUNGER, state);
    }

    public static void setPlungerFireCount(final int count) {
        WkwDashboard.getInstance().setStatus(WkwDashboard.STATUS_NAME_PLUNGER_FIRE_COUNT, count);
    }

    public static void setAccelX(final double pX) {
        WkwDashboard.getInstance().setStatus("Acceleromter-x", pX);
    }

    public static void setAccelY(final double pY) {
        WkwDashboard.getInstance().setStatus("Acceleromter-y", pY);
    }

    public static void setAccelZ(final double pZ) {
        WkwDashboard.getInstance().setStatus("Acceleromter-z", pZ);
    }
}
